// 单个会话对象类型
import {request} from "@/apis/request.ts";
const token = localStorage.getItem("token");
export interface ChatSessionParams {
    chatId?: number;
    userId?: number;
    summary?: string;
}

export interface ChatSessionItem {
    chatId: number;
    userId: number;
    summary: string;
}

// 接口返回结构
export interface ChatSessionsRes<T> {
    code: number;
    message: string;
    data: T;
}

// 获取用户所有会话
const getChatSessionsByUserId = async (userId: number): Promise<ChatSessionsRes<ChatSessionItem[]>> => {
    const token = localStorage.getItem("token");
    return request<ChatSessionsRes<ChatSessionItem[]>>(`/api/chat-sessions/${userId}`, {
        method: 'GET',
        headers: {
            'Authorization': `Bearer ${token}`,
        },
    })
}
const deleteChatSessionByUserId = async (userId: number): Promise<ChatSessionsRes<number>> => {
    const token = localStorage.getItem("token");
    return request<ChatSessionsRes<number>>(`/api/chat-sessions/${userId}`, {
        method: 'DELETE',
        headers: {
            'Authorization': `Bearer ${token}`,
        },
    })
}
const addChatSession = async (params:ChatSessionParams): Promise<ChatSessionsRes<ChatSessionItem>> => {
    const token = localStorage.getItem("token");
    return request<ChatSessionsRes<ChatSessionItem>>(`/api/chat-sessions/addChatSession`, {
        method: 'POST',
        headers: {
            'Authorization': `Bearer ${token}`,
        },
        data: params,
    })
}

export {getChatSessionsByUserId, deleteChatSessionByUserId, addChatSession}
